//
//  MainHandleTableCell.m
//  ProjectforHDX
//
//  Created by Jaesun on 16/6/30.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "MainHandleTableCell.h"

#define CELL_HEIGHT 115
#define CELL_STSTUE_HEIGHT 50
#define CELL_LABEL_HEIGHT 32
#define CELL_STEP_LABEL_HEIGHT 25
#define CELL_POINT_HEIGHT 10
#define CELL_LINE_HEIGHT 1.5
#define CELL_LINE_COLOR  [UtilCheck hexStringToColor:@"e5e5e5" alpha:1]
@interface MainHandleTableCell()
@property(nonatomic,strong) UIView *cellContentView;
@property(nonatomic,strong) UIView *headerView;
@property(nonatomic,strong) UIView *setpView;

@property(nonatomic,strong) RZCustomLable *labOrderCode;
@property(nonatomic,strong) RZCustomLable *labDate;

@property(nonatomic,strong) RZCustomLable *labStatus;

@property(nonatomic,strong) RZCustomLable *labTitle;

@property(nonatomic,strong) RZCustomLable *orderTypeLab;

@property(nonatomic,strong) RZCustomImageView *rightIcon;

@property(nonatomic,strong) RZCustomButtom *btnOpen;
    
@property(nonatomic,strong) UIImageView *iconimageView;




@end
@implementation MainHandleTableCell


- (void)setModel:(OrderModel *)model {
    
    if (_model != model) {
        _model=model;
        
//        _model.process =
        self.cellContentView=[[UIView alloc] init];
        [self.cellContentView setClipsToBounds:YES];
        [self.cellContentView setBackgroundColor:[UtilCheck getRZColor:244 green:248 blue:251 alpha:1]];
        [self addSubview:self.cellContentView];
        
        self.headerView=[[UIView alloc] init];
        [self.headerView setClipsToBounds:YES];
        [self.headerView setBackgroundColor:[UtilCheck hexStringToColor:@"ffffff" alpha:1]];
        [self.cellContentView addSubview:self.headerView];
        
        self.labOrderCode=[[RZCustomLable alloc] init];
        [self.labOrderCode setFont:CustomFont(13)];
        [self.labOrderCode setTextColor:[UtilCheck hexStringToColor:@"9d9fa1" alpha:1] ];
        [self.headerView addSubview:self.labOrderCode];
        
        self.labDate=[[RZCustomLable alloc] init];
        [self.labDate setFont:CustomFont(13)];
        [self.labDate setTextColor:[UtilCheck hexStringToColor:@"9d9fa1" alpha:1] ];
        [self.headerView addSubview:self.labDate];
        
        self.labStatus=[[RZCustomLable alloc] init];
        [self.labStatus setFont:CustomFont(13)];
        [self.labStatus setTextColor:[UtilCheck hexStringToColor:@"ffffff" alpha:1] ];
        self.labStatus.textAlignment=NSTextAlignmentCenter;
        [self.headerView addSubview:self.labStatus];
       
        self.iconimageView = [[UIImageView alloc]init];
        self.iconimageView.image = [UIImage imageNamed:@"订单"];
        [self.headerView addSubview:self.iconimageView];
        
        
        self.labTitle=[[RZCustomLable alloc] init];
        [self.labTitle setFont:CustomFont(16)];
        [self.labTitle setTextColor:[UtilCheck hexStringToColor:@"393939" alpha:1] ];
        [self.headerView addSubview:self.labTitle];
        
        self.orderTypeLab=[[RZCustomLable alloc] init];
        [self.orderTypeLab setFont:CustomFont(14)];
        [self.orderTypeLab setTextColor:[UtilCheck hexStringToColor:@"a1a1a1" alpha:1] ];
        [self.headerView addSubview:self.orderTypeLab];
        
        self.rightIcon=[[RZCustomImageView alloc] init];
        [self.rightIcon setImage:BDFILEIMAGENAEM(@"default/iconfont-jinru")];
        [self.headerView addSubview:self.rightIcon];
        
        if(self.iscunquHome==NO){
        self.btnOpen=[[RZCustomButtom alloc] init];
        [self.btnOpen setImage:BDFILEIMAGENAEM(@"Home/btn_drop") forState:UIControlStateNormal];
        [self.btnOpen setImage:BDFILEIMAGENAEM(@"Home/btn_close") forState:UIControlStateSelected];
        self.btnOpen.imageEdgeInsets = UIEdgeInsetsMake(20, 0, -20, 0);
        [self.btnOpen addTarget:self action:@selector(btnOpen:) forControlEvents:UIControlEventTouchUpInside];
        [self.headerView addSubview:self.btnOpen];
        }
    }
}

    
- (void)layoutSubviews {
   
    [self.cellContentView setFrame:CGRectMake(0, 0, self.width, self.height)];
    
    CGFloat cell_height;
    NSLog(@"_model.customer.length: %lu",(unsigned long)_model.customer.length);
    if (_model.customer.length > 17) {
        cell_height = CELL_HEIGHT + 15;
    }
    else {
        cell_height = CELL_HEIGHT - 7;
    }
    
    [self.headerView setFrame: CGRectMake(0, 0, self.cellContentView.width, cell_height)];
    
    //上面的分割线
    UILabel *upLine = [[UILabel alloc]init];
    [upLine setFrame:CGRectMake(0, 0 , self.width, 0.5)];
    [upLine setBackgroundColor:[Toolobject getColorByHexString:@"#e5e5e5" alpha:1]];
    [self.cellContentView addSubview:upLine];
    
    //下面的分割线
    UILabel *bottomLine = [[UILabel alloc]init];
    [bottomLine setFrame:CGRectMake(0, self.headerView.height - 0.5 , self.width, 0.5)];
    [bottomLine setBackgroundColor:[Toolobject getColorByHexString:@"#e5e5e5" alpha:1]];
    [self.cellContentView addSubview:bottomLine];
    
    //订单号
    [self.labOrderCode setFrame:CGRectMake(10, 0, self.headerView.width-20, CELL_LABEL_HEIGHT)];
    self.labOrderCode.text= self.iscunquHome==NO ? [NSString stringWithFormat:@"%@ :%@",[THMangerTool language:@"main.orderCode"],_model.orderCode]:[NSString stringWithFormat:@"%@ :%@",[THMangerTool language:@"main.cunjianCode"],_model.code];
    if (self.isqujian==YES) {
        self.labOrderCode.text = [NSString stringWithFormat:@"%@ :%@",[THMangerTool language:@"main.orderCode"],_model.code];
    }
    self.labOrderCode.numberOfLines=1;
    [self.labOrderCode sizeToFit];
    self.labOrderCode.left=10;
    self.labOrderCode.height=CELL_LABEL_HEIGHT;
    //日期
    [self.labDate setFrame:CGRectMake(10, 0, self.headerView.width-20, CELL_LABEL_HEIGHT)];
    self.labDate.text= self.iscunquHome==NO ? _model.date : _model.time;
    self.labDate.numberOfLines=1;
    [self.labDate sizeToFit];
    self.labDate.left=self.headerView.width-self.labDate.width-10;
    self.labDate.height=self.labOrderCode.height;
    
    //线
    [self.headerView addSoldLine:0.5 soldcolor:CELL_LINE_COLOR pointA:CGPointMake(0, self.labOrderCode.bottom) pointB:CGPointMake(self.headerView.width, self.labOrderCode.bottom)];
    
    //线1
    [self.headerView addSoldLine:0.5 soldcolor:CELL_LINE_COLOR pointA:CGPointMake(0, self.headerView.height) pointB:CGPointMake(self.headerView.width,self.headerView.height)];
    
    //订单状态
    [self.labStatus setFrame:CGRectMake(10,self.labOrderCode.height+(self.headerView.height-self.labOrderCode.height-CELL_STSTUE_HEIGHT)/2.f, CELL_STSTUE_HEIGHT, CELL_STSTUE_HEIGHT)];
    if (self.iscunquHome==YES) {
    [self.iconimageView setFrame:CGRectMake(10,self.labOrderCode.height+(self.headerView.height-self.labOrderCode.height-CELL_STSTUE_HEIGHT)/2.f, CELL_STSTUE_HEIGHT, CELL_STSTUE_HEIGHT)];
    }

    
    self.labStatus.font = CustomFont(10);
    self.labStatus.text= _model.typeName;
    self.labStatus.layer.masksToBounds=YES;
    self.labStatus.layer.cornerRadius=self.labStatus.width/2.f;
//    "type":订单类型,0已取消，1已完成，2待收货，3仓库待发货，4待安排发货,5待确认，6已完成
    
    
    // 黄色：253，186，69
    // 橘色: 253,158,88
    // 蓝色：77，170，271
    // 绿色：69，202，145
    
    UIColor *orderStatusColorYellow = [UtilCheck  getRZColor:253 green:186 blue:69 alpha:1];
    UIColor *orderStatusColorOrange = [UtilCheck  getRZColor:253 green:158 blue:88 alpha:1];
    UIColor *orderStatusColorBlue = [UtilCheck  getRZColor:77 green:170 blue:271 alpha:1];
    UIColor *orderStatusColorGreen = [UtilCheck  getRZColor:69 green:202 blue:145 alpha:1];
    
    if([_model.type isEqualToString:@"5"]){
        
        [self.labStatus setBackgroundColor:[UtilCheck  getRZColor:240 green:162 blue:91 alpha:1]];
    }
    else  if([_model.type isEqualToString:@"2"])
    {
        [self.labStatus setBackgroundColor:[UtilCheck  getRZColor:74 green:166 blue:225 alpha:1]];
    }
    else  if([_model.type isEqualToString:@"6"])
    {
        [self.labStatus setBackgroundColor:[UtilCheck  getRZColor:108 green:198 blue:148 alpha:1]];
    }
    else  if([_model.type  isEqualToString:@"1"])
    {
        [self.labStatus setBackgroundColor:[UtilCheck  getRZColor:67 green:202 blue:144 alpha:1]];
    }
    else  if([_model.type isEqualToString:@"3"])
    {
        [self.labStatus setBackgroundColor:[UtilCheck  getRZColor:240 green:162 blue:91 alpha:1]];
    }
    else  if([_model.type isEqualToString:@"0"])
    {
        [self.labStatus setBackgroundColor:[UIColor redColor]];
    }
    else  if([_model.type isEqualToString:@"4"])
    {
        [self.labStatus setBackgroundColor:[UtilCheck  getRZColor:244 green:190 blue:89 alpha:1]];
    }
    
    else  if([_model.type isEqualToString:@"-2"])
    {
        [self.labStatus setBackgroundColor:orderStatusColorYellow];
    }


    else{
        [self.labStatus setBackgroundColor:[UtilCheck  getRZColor:98 green:166 blue:226 alpha:1]];
    }
    
    //标题
    [self.labTitle setFrame:CGRectMake(10, self.labStatus.top + 3, self.headerView.width-95, CELL_LABEL_HEIGHT)];
    self.labTitle.text=self.iscunquHome==NO ? _model.customer : _model.storeName;
    self.labTitle.adjustsFontSizeToFitWidth=NO;
    self.labTitle.numberOfLines=2;
    [self.labTitle sizeToFit];
    self.labTitle.left=self.labStatus.right+10;
    if(self.labTitle.height<CELL_LABEL_HEIGHT){
        self.labTitle.height=CELL_LABEL_HEIGHT;
    }
    CGFloat cell_step_label_height;
    
    if (_model.customer.length > 17) {
        cell_step_label_height = CELL_STEP_LABEL_HEIGHT - 15;
    }
    else {
        cell_step_label_height = CELL_STEP_LABEL_HEIGHT;
    }
    
    [self.orderTypeLab setFrame:CGRectMake(10, self.labStatus.bottom-cell_step_label_height - 3, self.headerView.width-95, CELL_LABEL_HEIGHT)];
    if(self.iscunquHome==NO){
    //日期-->改为显示订单类型
    switch ([_model.orderType integerValue]) {
        case 1:
            self.orderTypeLab.text= [THMangerTool language:@"orderlist.type.management"];
            break;
        case 2:
            self.orderTypeLab.text=[THMangerTool language:@"orderlist.type.replace"];//@"备件替换订单";
            break;
        case 3:
            self.orderTypeLab.text=[THMangerTool language:@"orderlist.type.repair"];//@"本地返修订单";
            break;
        case 4:
            self.orderTypeLab.text=[THMangerTool language:@"orderlist.type.test"];//@"测试订单";
            break;
        case 5:
            self.orderTypeLab.text=[THMangerTool language:@"orderlist.type.To borrow"];//@"借用订单";
            break;
        case 6:
            self.orderTypeLab.text=[THMangerTool language:@"orderlist.type.The cargo"];//@"调货订单";
            break;
        case 7:
            self.orderTypeLab.text=[THMangerTool language:@"orderlist.type.Replace delivery"];//@"备件替换发货订单";
            break;
        case 8:
            self.orderTypeLab.text=[THMangerTool language:@"orderlist.type.Failure parts"];//@"故障件送修订单";
            break;
        case 9:
            self.orderTypeLab.text=[THMangerTool language:@"orderlist.type.procurement"];//@"备件采购订单";
            break;
        case 10:
            self.orderTypeLab.text=[THMangerTool language:@"orderlist.type.replenishment"];//@"补货订单";
            break;
        case 11:
            self.orderTypeLab.text=[THMangerTool language:@"orderlist.type.scrap"];//@"报废订单";
            break;
        default:
            self.orderTypeLab.text=[THMangerTool language:@"orderlist.type.servers data error"];//@"服务器返回的订单类型有问题";
            break;
    }
    }
    else{
        self.orderTypeLab.text = [NSString stringWithFormat:@"箱号:%@",_model.boxCode];
    }
    
    self.orderTypeLab.numberOfLines=1;
    [self.orderTypeLab sizeToFit];
    // self.orderTypeLab.top = self.labTitle.bottom;
    self.orderTypeLab.left = self.labStatus.right+10;
    self.orderTypeLab.height=CELL_LABEL_HEIGHT;
    
    //右按钮
    [ self.rightIcon setFrame:CGRectMake(self.headerView.width-20,self.labOrderCode.height+(self.headerView.height-self.labOrderCode.height-14)/2.f, 7, 14)];
    
    //按钮
    [self.btnOpen setFrame:CGRectMake((self.headerView.width-80)/2.f,self.headerView.height-50, 80, 50)];
    
    self.btnOpen.selected=_model.open;
    
    if(_model.open){
        [self.setpView setBackgroundColor:[UtilCheck hexStringToColor:LineColor alpha:1]];
        [self.cellContentView addSubview:self.setpView];
        self.setpView=[self createStepView:_model];
        [self.setpView setBackgroundColor:[UtilCheck hexStringToColor:@"ffffff" alpha:1]];
        self.setpView.top=self.headerView.bottom;
        [self.cellContentView addSubview:self.setpView];
    }
    else{
        [self.setpView removeFromSuperview];
    }
    
    
    
    
}


-(UIView*)createStepView:(OrderModel*)model{
    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, 0)];
    CGFloat height=0;
    NSArray *arr=model.process;
    if(![arr isKindOfClass:[NSArray class]]){
        return view;
    }
    int  count=(int)arr.count;
    for(int i=0;i<count;i++){
        NSDictionary *dict=[arr objectAtIndex:i];
        
        //流程层
        UIView *itemView=[[UIView alloc] initWithFrame:CGRectMake(0, height, view.width, 0)];
        [view addSubview:itemView];
        
        //名称
        RZCustomLable *labStepTitle=[[RZCustomLable alloc] init];
        [labStepTitle setFrame:CGRectMake(10, 10, self.headerView.width-80, CELL_STEP_LABEL_HEIGHT)];
        labStepTitle.text=[[dict objectForKey:@"stepInfo"] objectForKey:@"stepName"];
        labStepTitle.numberOfLines=4;
        [labStepTitle setFont:CustomFont(15)];
        [labStepTitle sizeToFit];
        labStepTitle.left=30;
        if(labStepTitle.height<25){
            labStepTitle.height=25;
        }
        [itemView addSubview:labStepTitle];
        
        
        
        
        if( 2==[[dict objectForKey:@"style"] intValue])
        {
            //职业
            RZCustomLable *labJob=[[RZCustomLable alloc] init];
            [labJob setFrame:CGRectMake(10, labStepTitle.bottom, 100, CELL_STEP_LABEL_HEIGHT)];
            labJob.text=[[dict objectForKey:@"stepInfo"] objectForKey:@"role"];
            labJob.numberOfLines=1;
            [labJob setFont:CustomFont(14)];
            [labJob sizeToFit];
            [labJob setTextColor:[UtilCheck hexStringToColor:@"999999" alpha:1]];
            labJob.left=labStepTitle.left;
            if(labJob.height<CELL_STEP_LABEL_HEIGHT){
                labJob.height=CELL_STEP_LABEL_HEIGHT;
            }
            [itemView addSubview:labJob];
            
            NSString *userName=[[dict objectForKey:@"stepInfo"] objectForKey:@"userRealName"];
            UIImage *telImage =BDFILEIMAGENAEM(@"Home/btn_ringup");
            CGSize size= [UtilCheck sizeWithString:userName CGsize:CGSizeMake(120, CELL_STEP_LABEL_HEIGHT) font:CustomFont(13)];
            //姓名
            RZCustomButtom *btnUser=[[RZCustomButtom alloc] init];
            [btnUser setTitle:userName forState:UIControlStateNormal];
            
            [btnUser setFrame:CGRectMake(labJob.right+5, labJob.top, size.width+15+telImage.size.width, labJob.height)];
            [btnUser setImage:telImage forState:UIControlStateNormal];
            [btnUser textleftimageright:NSTextLeft BothInterval:10];
            [btnUser setTag:101+i];
            [btnUser setTitleColor:[UtilCheck getRZColor:68 green:136 blue:237 alpha:1] forState:UIControlStateNormal];
            [btnUser setTitleColor:[UtilCheck getRZColor:68 green:136 blue:237 alpha:1] forState:UIControlStateHighlighted];
            [btnUser.titleLabel setFont:CustomFont(13)];
            [btnUser addTarget:self action:@selector(Tel:) forControlEvents:UIControlEventTouchUpInside];
            [itemView addSubview:btnUser];
            
            //快递职业
            RZCustomLable *labCourierJob=[[RZCustomLable alloc] init];
            [labCourierJob setFrame:CGRectMake(10, labJob.top, 100, CELL_STEP_LABEL_HEIGHT)];
            labCourierJob.text=[[dict objectForKey:@"stepInfo"] objectForKey:@"courier"];
            labCourierJob.numberOfLines=1;
            [labCourierJob setTextColor:[UtilCheck hexStringToColor:@"999999" alpha:1]];
            [labCourierJob setFont:labJob.font];
            [labCourierJob sizeToFit];
            labCourierJob.left=btnUser.right+5;
            if(labCourierJob.height<CELL_STEP_LABEL_HEIGHT){
                labCourierJob.height=CELL_STEP_LABEL_HEIGHT;
            }
            [itemView addSubview:labCourierJob];
            
            NSString *courierName=[[dict objectForKey:@"stepInfo"] objectForKey:@"courierTel"];
            
            size= [UtilCheck sizeWithString:courierName CGsize:CGSizeMake(120, CELL_STEP_LABEL_HEIGHT) font:CustomFont(13)];
            //电话
            RZCustomButtom *btnCourier=[[RZCustomButtom alloc] init];
            [btnCourier setTitle:courierName forState:UIControlStateNormal];
            
            [btnCourier setFrame:CGRectMake(labCourierJob.right+5, labJob.top, size.width+10 , labJob.height)];
            
            [btnCourier textleftimageright:NSTextLeft BothInterval:10];
            [btnCourier setTag:101+i];
            [btnCourier setTitleColor:[UtilCheck getRZColor:68 green:136 blue:237 alpha:1] forState:UIControlStateNormal];
            [btnCourier setTitleColor:[UtilCheck getRZColor:68 green:136 blue:237 alpha:1] forState:UIControlStateHighlighted];
            [btnCourier.titleLabel setFont:CustomFont(13)];
            [btnCourier addTarget:self action:@selector(CourierTel:) forControlEvents:UIControlEventTouchUpInside];
            [itemView addSubview:btnCourier];
            
            //超出部分
            if(btnCourier.right>itemView.width-20){
                labCourierJob.top=labJob.bottom;
                labCourierJob.left=labJob.left;
                btnCourier.top=labCourierJob.top;
                btnCourier.left=labCourierJob.right+5;
                
            }
            itemView.height=btnCourier.bottom + 10;
            
        }
        else if(3==[[dict objectForKey:@"style"] intValue]){
            //职业
            RZCustomLable *labJob=[[RZCustomLable alloc] init];
            [labJob setFrame:CGRectMake(10,  labStepTitle.bottom, 100, CELL_STEP_LABEL_HEIGHT)];
            labJob.text=[[dict objectForKey:@"stepInfo"] objectForKey:@"role"];
            labJob.numberOfLines=1;
            [labJob setFont:CustomFont(14)];
            [labJob sizeToFit];
            [labJob setTextColor:[UtilCheck hexStringToColor:@"999999" alpha:1]];
            labJob.left=labStepTitle.left;
            if(labJob.height<CELL_STEP_LABEL_HEIGHT){
                labJob.height=CELL_STEP_LABEL_HEIGHT;
            }
            [itemView addSubview:labJob];
            
            NSString *userName=[[dict objectForKey:@"stepInfo"] objectForKey:@"userRealName"];
            UIImage *telImage =BDFILEIMAGENAEM(@"Home/btn_ringup");
            CGSize size= [UtilCheck sizeWithString:userName CGsize:CGSizeMake(120, CELL_STEP_LABEL_HEIGHT) font:CustomFont(13)];
            //姓名
            RZCustomButtom *btnUser=[[RZCustomButtom alloc] init];
            [btnUser setTitle:userName forState:UIControlStateNormal];
            
            [btnUser setFrame:CGRectMake(labJob.right+5, labJob.top, size.width+15+telImage.size.width, labJob.height)];
            [btnUser setImage:telImage forState:UIControlStateNormal];
            [btnUser textleftimageright:NSTextLeft BothInterval:10];
            [btnUser setTag:101+i];
            [btnUser setTitleColor:[UtilCheck hexStringToColor:@"38adff" alpha:1] forState:(UIControlStateNormal)];
            [btnUser setTitleColor:[UtilCheck hexStringToColor:@"38adff" alpha:1]  forState:UIControlStateHighlighted];
            
            [btnUser.titleLabel setFont:CustomFont(13)];
            [btnUser addTarget:self action:@selector(Tel:) forControlEvents:UIControlEventTouchUpInside];
          
            
            [itemView addSubview:btnUser];
            
            itemView.height=btnUser.bottom + 10;
        }
        
        else if(-1 ==[[dict objectForKey:@"style"] intValue]){
            //内容
            CustomLabel *labContent=[[CustomLabel alloc] initWithFrame:CGRectMake(labStepTitle.left, labStepTitle.bottom, self.headerView.width-80, 300)];
            [labContent setFont:CustomFont(14)];
            NSString *htmlString=[[dict objectForKey:@"stepInfo"] objectForKey:@"stepContent"];
            NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
            
            
            labContent.attributedText=attrStr;
            labContent.numberOfLines=4;
            [labContent setTextColor:[UtilCheck hexStringToColor:@"999999" alpha:1]];
            CGSize size=[labContent  preferredSizeWithMaxWidth:self.headerView.width-80];
            labContent.width=size.width;
            labContent.height=size.height;
            if(labContent.height<CELL_STEP_LABEL_HEIGHT){
                labContent.height=CELL_STEP_LABEL_HEIGHT;
            }
            [itemView addSubview:labContent];
            itemView.height=labContent.bottom + 10 ;

        }
        
        else{
            //内容
            CustomLabel *labContent=[[CustomLabel alloc] initWithFrame:CGRectMake(labStepTitle.left, labStepTitle.bottom, self.headerView.width-80, 300)];
            [labContent setFont:CustomFont(14)];
            NSString *htmlString=[[dict objectForKey:@"stepInfo"] objectForKey:@"stepContent"];
            NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
            
            
            labContent.attributedText=attrStr;
            labContent.numberOfLines=4;
            [labContent setTextColor:[UtilCheck hexStringToColor:@"999999" alpha:1]];
            CGSize size=[labContent  preferredSizeWithMaxWidth:self.headerView.width-80];
            labContent.width=size.width;
            labContent.height=size.height;
            if(labContent.height<CELL_STEP_LABEL_HEIGHT){
                labContent.height=CELL_STEP_LABEL_HEIGHT;
            }
            [itemView addSubview:labContent];
            itemView.height=labContent.bottom + 10 ;
        }
        //按钮
        RZCustomButtom *btnRight=[[RZCustomButtom alloc] init];
        [btnRight setTitle:[[dict objectForKey:@"stepInfo"] objectForKey:@"date"] forState:UIControlStateNormal];
        
        [btnRight setFrame:CGRectMake(itemView.width-100, (itemView.height-20)/2.f, 90, 20)];
        if (btnRight.titleLabel.text.length <= 3) {
            [btnRight setFrame:CGRectMake(itemView.width-60, (itemView.height-20)/2.f, 40, 20)];
        }

        [btnRight addRadius:btnRight.height/2.f borderwidth:0.5 bordercolor:[UtilCheck hexStringToColor:@"c7c7cc" alpha:1]];
        [btnRight.titleLabel setFont:CustomFont(11)];
        btnRight.tag=101+i;
        [btnRight addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        if ([[dict objectForKey:@"style"] intValue] != -1) {//
            [itemView addSubview:btnRight];
        }
        
        //圈
        RZCustomLable *labPoint=[[RZCustomLable alloc] init];
        [labPoint setFrame:CGRectMake(10, labStepTitle.top+(labStepTitle.height-CELL_POINT_HEIGHT)/2.f, CELL_POINT_HEIGHT, CELL_POINT_HEIGHT)];
        [labPoint addRadius:labPoint.width/2.f borderwidth:2 bordercolor:[UtilCheck hexStringToColor:@"ffff00" alpha:1]];
        [labPoint setBackgroundColor:[UtilCheck hexStringToColor:@"ffffff" alpha:1]];
        
        //线
        RZCustomLable *labLine=[[RZCustomLable alloc] init];
        [labLine setFrame:CGRectMake(10+(CELL_POINT_HEIGHT-CELL_LINE_HEIGHT)/2.f, 0, CELL_LINE_HEIGHT, itemView.height)];
        [labLine setBackgroundColor:[UtilCheck getRZColor:229  green:230 blue:231 alpha:1]];
        [itemView addSubview:labLine];
        
        [itemView addSubview:labPoint];
       
        //处理圈和线的问题
        if(i==0){
            
            labLine.top=labPoint.top;
            
            [labPoint addRadius:labPoint.width/2.f borderwidth:2 bordercolor:[UtilCheck getRZColor:251 green:158 blue:89 alpha:1]];
            [labPoint setBackgroundColor:[UtilCheck getRZColor:251 green:158 blue:89 alpha:1]];
            
            btnRight.backgroundColor = [UtilCheck hexStringToColor:@"38adff" alpha:1];
            [btnRight setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
            [btnRight addRadius:btnRight.height/2.f borderwidth:0.5 bordercolor:[UIColor whiteColor]];
        }
        else if(i==count-1){
            labLine.height=labPoint.top;
            [labPoint addRadius:labPoint.width/2.f borderwidth:2 bordercolor:[UtilCheck getRZColor:229  green:230 blue:231 alpha:1]];
            [labPoint setBackgroundColor:[UtilCheck hexStringToColor:@"ffffff" alpha:1]];
            
            
        }
        else
        {
            [labPoint addRadius:labPoint.width/2.f borderwidth:2 bordercolor:[UtilCheck getRZColor:229  green:230 blue:231 alpha:1]];
            [labPoint setBackgroundColor:[UtilCheck hexStringToColor:@"ffffff" alpha:1]];
            
        }
        
        // 如果只有一个步骤是不要流程线
        if (count == 1) {
            [labLine removeFromSuperview];
        }
        
        height=itemView.bottom;
    }
    
    view.height=height;
    
    //线1
    [view addSoldLine:1 soldcolor:CELL_LINE_COLOR pointA:CGPointMake(0,view.height) pointB:CGPointMake(view.width,view.height)];
    
    
    return view;
    
}

-(void)Tel:(RZCustomButtom*)sender{
    if(_model){
        NSArray *arr=_model.process;
        NSDictionary *dict=[arr objectAtIndex:sender.tag-101];
        [self goTel:[[dict objectForKey:@"stepInfo"] objectForKey:@"userTel"]];
    }
    
}

-(void)CourierTel:(RZCustomButtom*)sender{
    if(_model){
        NSArray *arr=_model.process;
        NSDictionary *dict=[arr objectAtIndex:sender.tag-101];
        [self goTel:[[dict objectForKey:@"stepInfo"] objectForKey:@"courierTel"]];
    }
}
/**
 *  拨打电话
 *
 *  @param mobile
 */
-(void)goTel:(NSString*)mobile{
    NSString *str = [NSString stringWithFormat:@"tel:%@",mobile];
    UIWebView *callWebview =[[UIWebView alloc] init];
    NSURL *telURL =[NSURL URLWithString:str];
    [callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
    //记得添加到view上
    [self.delegateVC.view addSubview:callWebview];
    
    
}

//流程按钮
-(void)btnOpen:(RZCustomButtom*)sender{
    sender.selected=!sender.selected;
    
    _model.open=sender.selected;
    if (_model.open == YES) {
        [self requestProcess];
    }
    else{
        if(self.Refesh){
            self.Refesh(_model);
        }
 
    }
    
}
//流程按钮
-(void)btnClick:(RZCustomButtom*)sender{
    
}

/**
 *  订单流程查询接口
 */
- (void)requestProcess {
    
    [[BDHUD sharedManager] showBDHUD:self.superview.superview title:nil];

    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"orderCode"]=self.model.orderCode;
    [AFHttpTool postJsonDatawithUrl:@"process"  parameters:[params mutableCopy] success:^(id responseObject) {
        
        [[BDHUD sharedManager] dismissHUD];
        
        if(1 == [[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue] ) {
            _model.process = [[NSMutableArray alloc]initWithArray:[responseObject objectForKey:@"data"]];
            self.Refesh(_model);
        }
        else {
            
            //返回数据出问题 弹出服务器返回信息
            if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
            }
        }
        
    } fail:^(id responseObject, NSError *error) {
        
        [[BDHUD sharedManager] dismissHUD];
        if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
        }else {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
        }
        
    }];
}

@end
